home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / vol15n11.zip / REXBOX.ZIP / STREAM.CMD < prev    next >
OS/2 REXX Batch file  |  1996-02-01  |  5KB  |  177 lines

  1. /* MCI REXX Sample #5 */
  2. /* this script shows you how to determine where the output of CD music*/
  3. /* goes.  It also illustrates how to poll the CD device to determine  */
  4. /* when it reaches a desired position                                 */
  5. /* The user specifies the track they wish to play and how long within */
  6. /* the track and we take care of the rest.                            */
  7.  
  8. signal on error /* When commands fail, call "error" routine. */
  9.  
  10.   call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  11.   call SysLoadFuncs
  12.  
  13. /* retrieve command line arguments for stream.cmd */
  14. parse arg arg1 arg2
  15.  
  16. If (arg1='') Then
  17.    do
  18.    /* users must send the track they wish to play */
  19.  
  20.    say 'Stream example command uses two parameters'
  21.    say 'stream TRACK [time]'
  22.    say 'TRACK specifies the track to play and is required.'
  23.    say 'time is option and specifies the amount of time in the track to play'
  24.    exit 1
  25.    End
  26. ELSE
  27.    do
  28.    track = arg1
  29.    END
  30.  
  31. /* Convert seconds into milliseconds (which we use for time calculations) */
  32.  
  33. If (arg2='') Then
  34.    do
  35.    maxtime = 10000
  36.    End
  37. ELSE
  38.    do
  39.    maxtime = arg2 * 1000
  40.    END
  41.  
  42. /* Initialize multimedia functions */
  43.  
  44. rc = RXFUNCADD('mciRxInit','MCIAPI','mciRxInit')
  45. rc = RXFUNCADD('mciRxGetErrorString','MCIAPI','mciRxGetErrorString')
  46.  
  47. InitRC = mciRxInit()
  48.  
  49. /* Open the CD */
  50.  
  51. rc = mciRxSendString("open cdaudio alias supercd wait", 'Retst', '0', '0')
  52.  
  53. /* Ensure that the user has a CD in the drive */
  54.  
  55. rc = mciRxSendString("status supercd media present wait", 'Retst', '0', '0')
  56. If Retst <> 'TRUE' then
  57.      do
  58.      say 'Must have CD inserted to run this command file'
  59.      say 'Please insert'
  60.      rc = mciRxSendString("status supercd media present wait", 'Retst', '0', '0')
  61.  
  62.        do while Retst <> 'TRUE'
  63.          rc = mciRxSendString("status supercd media present wait", 'Retst', '0', '0')
  64.        End
  65.      End
  66.  
  67.  
  68. rc = mciRxSendString("status supercd number of tracks wait", 'Retst', '0', '0')
  69. If track > Retst then
  70.     do
  71.       say 'CD only has ' Retst ' tracks'
  72.       rc = mciRxSendString("close supercd wait", 'Retst', '0', '0')
  73.       exit 1
  74.     End
  75.  
  76. /* ask the user if they want digital transfer */
  77.  
  78. say 'Use Digital Transfer (Y/N)'
  79.  
  80. quit = FALSE
  81.  
  82. do while quit <> 'TRUE'
  83.    keyin = SysGetKey('NOECHO')
  84.    IF keyin = 'Y' | keyin = 'y'
  85.      THEN
  86.        do
  87.        quit = TRUE
  88.        digital = 1
  89.        /* Ask the device if it supports digital transfer   */
  90.        /* Its always been to ask BEFORE rather than hoping */
  91.        /* it will work in the future.                      */
  92.  
  93.        rc = mciRxSendString("capability supercd can stream wait", 'Retst', '0', '0')
  94.  
  95.  
  96.        If Retst = 'TRUE' THEN
  97.           do
  98.  
  99.           /* This command enables digital transfer (if it is supported ) */
  100.           rc = mciRxSendString("connector supercd enable type cd stream wait", 'Retst', '0', '0')
  101.  
  102.           /* make sure the command works */
  103.  
  104.           IF rc <> 0 THEN
  105.              do
  106.              /* mciRxGetErrorString  takes an error and returns an error message */
  107.  
  108.              frc = mciRxGetErrorString(rc, 'errstr')
  109.              say 'Digital Transfer error was : ' errstr
  110.              say 'Using normal playback instead'
  111.              END
  112.           ELSE
  113.             say 'Digital Transfer enabled for ' maxtime / 1000 ' seconds'
  114.    
  115.            END
  116.         END
  117.        ELSE
  118.          say "this drive doesn't support digital transfer--sorry"
  119.    IF keyin = 'n' | keyin = 'n'
  120.      THEN
  121.        do
  122.        quit = TRUE
  123.        digital = 1
  124.        say 'Normal playback in use for 'maxtime / 1000' seconds'
  125.        END
  126.  
  127. END
  128.  
  129. /* we will set the time format to track oriented, then seek to the desired */
  130. /* track.  When you are in track-minutes-seconds-frames format, its easy   */
  131. /* to perform track oriented manipulations.                                */
  132.  
  133. rc = mciRxSendString("set supercd time format tmsf wait", 'Retst', '0', '0')
  134. seekcommand = 'seek supercd to' track ' wait'
  135. rc = mciRxSendString(seekcommand, 'Retst', '0', '0')
  136.  
  137. /* calculate time offsets from the beginning of the track                  */
  138. /* use milliseconds since its easier to determine time offsets in this     */
  139. /* rather than converting a track offset into a time unit                  */
  140.  
  141. rc = mciRxSendString("set supercd time format ms wait", 'Retst', '0', '0')
  142. rc = mciRxSendString("status supercd position wait", 'time', '0', '0')
  143.  
  144. rc = mciRxSendString("play supercd ", 'Retst', '0', '0')
  145.  
  146. maxtime = maxtime + time
  147.  
  148. /* loop until the desire number of milliseconds have passed */
  149.  
  150. do while time < maxtime
  151.   rc = mciRxSendString("status supercd position wait", 'time', '0', '0')
  152.   END
  153.  
  154.  
  155. rc = mciRxSendString("close supercd wait", 'Retst', '0', '0')
  156.  
  157. say 'Finished SuperCD streaming example'
  158. exit
  159.  
  160.  
  161. error:
  162.    say 'Error' ErrRC 'at line' sigl ', sourceline:' sourceline(sigl)
  163.    say 'Terminating'
  164.    mciRxSendString("close supercd wait", 'Retst', '0', '0')
  165.    mciRxExit()               /* Tell the DLL we're going away */
  166.    exit ErrRC                /* exit, tell caller things went poorly */
  167.  
  168. halt:
  169. /*
  170.  * Close all device alias's, in case we previously killed
  171.  * this batch file in the same process.
  172.  */
  173.    say 'Terminating'
  174.   mciRxSendString("close supercd wait", 'Retst', '0', '0')
  175. exit
  176.  
  177.